package day07_快速排序;

public class leetcode_荷兰国旗问题 {
    public void sortColors(int[] nums) {
        if (nums == null || nums.length < 2) {
            return;
        }

        int cur = 0; // 循环遍历的指针i
        int l = -1; //最左边的指针l
        int r = nums.length; //最右边的指针r
        while (cur < r) {
            if (nums[cur] < 1) {
                swap(nums, cur++, ++l);
            } else if (nums[cur] == 1) {
                cur++;
            } else {
                swap(nums, cur, --r);
            }
        }

    }

    private static void swap(int[] arr, int i, int j) {
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }
}
